	var addressIp = "http://1.14.68.137:8000/";
	var dataArr = null;
	
	/* 鼠标移上 */
	var $ho = $(".hover");
	$(".head_img").hover(function () {
		$ho.stop().fadeIn(200);
	}, function () {
		$ho.stop().fadeOut(200);
	})
	
	
	var cookie = document.cookie
	/* 先截取到问号后面的所有字符串，不包括问号 */
	cookie = cookie.substring(cookie.indexOf("?") + 1);
	// 查看字符串，找找其中的规律，
	// 把字符串按&转换为数组
	var arr = cookie.split("; ");
	/* 定义一个对象 */
	var cookieObj = {};
	/* 使用for循环让转换为数组中的每个字符串转换为新创建对象的属性 */
	for (var i = 0 ; i < arr.length ; i++) {
		cookieObj[arr[i].split("=")[0]] = arr[i].split("=")[1];
	};
	/* 获取uptoken */
	var uptoken = null;
	$.ajax({
		url: addressIp + "uptoken/",
		type: "GET",
		dataType: "json",
		headers: {
			token: cookieObj.token
		},
		success: function (x) {
			uptoken = x.uptoken;
		}
	});
	
	/* 添加文件事件 */
	var addHeadImg = $(".head_img>input");
	var head_img = $(".head_img>img");
	var imageIp = null;
	var imageKey = null;
	addHeadImg.change(function () {
		var file = this.files[0];
		if (!file) return
		var reader = new FileReader();
		reader.onload = function () {
			head_img.attr("src", reader.result)
		}
		reader.readAsDataURL(file);
		var observable = qiniu.upload(file, null, uptoken, null, {
			useCdnDomain: true,
			region: qiniu.region.z2
		});
		observable.subscribe({
			next(res) {
				
			},
			complete(res) {
				imageKey =  `http://cdn.maaoguo.top/${res.key}`;
				imageIp = `http://cdn.maaoguo.top/${res.hash}`;
			}
		});
	})
	/* 绑定上传事件 */
	var btn = $("#btn");
	btn.click(function () {
		if (head_img.attr("data-str") == imageIp || !imageIp) {
			alert("图片没变，请重新上传！");
			return
		}
		$.ajax({
			url: addressIp + "upuserimage/",
			type: "POST",
			dataType: "json",
			data: {
				url: imageIp
			},
			headers: {
				token: cookieObj.token
			},
			success: function (x) {
				alert(x.msg);
				// dataArr = x.data;
			}
		});
		detailed();
	})
	
	/* 获取用户详细信息 */
	var userNickname = $(".user_nickname");
	var userId = $(".user_id");
	var userEmail = $(".user_email");
	detailed();
	function detailed() {
		$.ajax({
			url: addressIp + "userinfo",
			type: "GET",
			dataType: "json",
			headers: {
				token: cookieObj.token
			},
			success: function (x) {
				console.log(x)
				if (x.code == -1) {
					alert(x.msg);
				}
				dataArr = x.data;
				head_img.attr("src", dataArr.imgurl);
				head_img.attr("data-str", dataArr.imgurl);
				userNickname.text(dataArr.username);
				userId.text(dataArr.id + "号");
				userEmail.text(dataArr.email);
			}
		});
	}
	var contNav = $(".cont_nav>ul>li");
	contNav.click(function () {
		var thisLi = $(this).attr("value");
		switch(thisLi) {
			case "user_data":
				
				break;
			case "user_address":
				location.href = "./receAddress.html"
				break;
			case "user_order":
				
				break;
		}
	})
	